getScript("/assets/biz-logic/js/amaze_icons.js"); 
getScript("/assets/common/nicescroll/jquery.nicescroll.min.js"); 
$(function(){
	
	/*$('#admin-menus li a.am-menu').click(function(){
		var url = $(this).data("url");
		amFun.toPage(url);
	});*/
	
	$("html").niceScroll({styler:"fb",cursorcolor:"#27AE60", cursorwidth: '4', cursorborderradius: '0px', background: '#E9E9E9', spacebarenabled:false, cursorborder: '0',  zindex: '1000'});;
	
	
	$('#admin-menus li a.am-menu').click(function(){
		var url = $(this).data("url");
		if(url != null && url != ''){
			$('#rightIframe').attr("src" , url);
		}
	});
	
	
	$('#am-offcanvas-btn').click(function(){
		var state = $("#admin-menus").data("offcanvas");
		state = state || false;
		if(!state){
			$('#admin-menus').animate({marginLeft: ('-'+$("#admin-menus").width()+'px')},'slow');
			$("#admin-menus").data("offcanvas", true);
			$(this).attr("title","打开侧边栏");
		}
		else{
			$('#admin-menus').animate({marginLeft: ('+0px')},'slow');
			$("#admin-menus").data("offcanvas", false);
			$(this).attr("title","隐藏侧边栏");
		}
	});
	
	amIcons.init();
});
 

var amIcons = {
	
	init : function(){
		var r = system_icons;
		for ( var i in r) {
			var icondiv = '<div class="am-padding" id="'+r[i].id+'">' 
			icondiv+= '<div class="am-text-primary">'+r[i].title+'</div>';
			var dlist = r[i].list;
			for ( var j in dlist) {
				icondiv += '<a class="am-inline-block border_dash am-btn-default admin-show-icons" style="padding:5px;margin:2px;" href="javascript:void(0);"><i class="'+dlist[j]+'"></i></a>';
			}	
		    icondiv += '</div>';
		    $('#icon_list_body').append(icondiv);
		}
	} 
		
} ;

var amFun = {
		
		history : {
			urls : new Array(),
			go : function(i , flag){
				if(amFun.history.urls.length < 0) return ;
				if(i < 0 && (amFun.history.urls.length + i) >= 1 ){
					amFun.toPage(amFun.history.urls[amFun.history.urls.length + i-1]);
				}
			}
		},
		
		/**
		 * 跳转到指定地址页面
		 * @param url
		 */
		toPage : function (url,params){
			if(url == '') return ;
			$.post(url, params, function(r) {
				var data = {};
				params = params || {} ;
				if(url.indexOf('\?') != -1){
					url = url.substring(url.indexOf('\?')+1 ,url.length);
					url = url.replace(/\+/g,"%20");
					url = url.replace(/&/g,"\",\"");
					url = url.replace(/=/g,"\":\"");
					data = eval("({\""+url +"\"})");
					$.each(data,function(i,n){ data[i] = $.trim(decodeURIComponent(n));});
				}
				$.each(params , function(i,n){ data[i] = n; });
				$('#admin-content').data("params" , data);
				$('#admin-content').html(r);
				amFun.history.urls.push(url);
		    }, 'text');
		} ,
		
		/**
		 * 获取页面跳转参数
		 */
		toPageParams : function (){
			return $('#admin-content').data("params");
		} ,
		
		includePage : function(url , params){
			var data = {};
			url = url || '';
			if(url == '' ) return ;
			$.post(url, params, function(r) {
				params = params || {} ;
				if(url.indexOf('\?') != -1){
					url = url.substring(url.indexOf('\?')+1 ,url.length);
					url = url.replace(/\+/g,"%20");
					url = url.replace(/&/g,"\",\"");
					url = url.replace(/=/g,"\":\"");
					data = eval("({\""+url +"\"})");
					$.each(data,function(i,n){ data[i] = $.trim(decodeURIComponent(n));});
				}
				$.each(params , function(i,n){ data[i] = n; });
				$('#admin-content').data("params" , data);
				$('#admin-content .admin-content').addClass("am-hide");
				$('#admin-content').append(r);
		    }, 'text');
		},
		showPageUp : function(){
			var size = $('#admin-content .admin-content:hidden').length;
			if(size <= 0) return ;
			$('#admin-content .admin-content:visible').remove();
			$($('#admin-content .admin-content:hidden')[size-1]).removeClass("am-hide");
		}
};
